import { get } from '@/utils/api-requester';
import { showErrorMsg, showSuccessMsg } from '@/components/exception/GlobalMessage';
import { merge } from 'lodash';

let url = '/get_sample_chart_data';

export default {
    namespace: 'sample_chart',
    state: {
        dataSource: [],
    },
    effects: {
        'getStatistic': function* ({ payload }, { put, call }) {
            try {
                let resp = yield call(get, url);
                const { error_code, data } = resp.data;
                if (error_code === 0) {
                    const payload = data;
                    yield put({ type: 'save', payload: payload });
                    showSuccessMsg('登陆成功!');
                } else {
                    throw new Error(data);
                }
            } catch (e) {
                yield put({ type: 'save', payload: { error: e }, error: true });
                showErrorMsg(e);//错误消息提示
            }
        },
    },
    reducers: {
        'save': (state, { payload }) => {
            let temp = merge({}, state);
            temp.dataSource = payload;
            return temp;
        },
    }
}
